package com.wc.alorithm_blue_bridge._思维.Q3332;

import java.io.*;

/**
 * @Author congege
 * @Description 迷失描述
 * https://www.lanqiao.cn/problems/3332/learning/?page=1&first_category_id=1
 * @Date Created in 2023/11/27-13:54
 */
public class Main {
    public static void main(String[] args) {

        Input sc = new Input();
        int n = sc.nextInt();

        // 存储元数组
        int[] array = new int[n + 1];
        // 头节点
        Node head = new Node(0);
        // 方便便利删除
        Node preNode = head;
        // 前缀或和数组
        int[] pre = new int[n + 1];
        // 答案数组
        int[] ansArray = new int[n + 1];

        int idx = 1;
        // 字典序类第一个数一定是最大的数
        int maxNum = 0;
        Node maxNode = new Node(0);

        for (int i = 1; i <= n; i++) {
            array[i] = sc.nextInt();
            preNode.next = new Node(array[i]);
            if (array[i] > maxNum) {
                maxNode = preNode;
                maxNum = array[i];
            }
            preNode = preNode.next;
        }
        // 把最大的数移除
        remove(maxNode);

        pre[idx] = maxNum;
        ansArray[idx] = maxNum;

        idx++;


        for (; idx <= n; idx++) {
            maxNum = 0;
            maxNode = new Node(0);
            preNode = head;
            // 遍历剩下的序列，查看哪一个与前缀或最大，就取这个数
            while (preNode.next != null) {
                int cal = pre[idx - 1] | preNode.next.val;
                if (cal > maxNum) {
                    maxNode = preNode;
                    maxNum = cal;
                }
                preNode = preNode.next;
            }
            // maxNum == pre[idx - 1] 说明后面的数就全部都一样了
            if (maxNum == pre[idx - 1]) {
                break;
            }
            pre[idx] = maxNum;
            ansArray[idx] = maxNode.next.val;
            remove(maxNode);

        }

        preNode = head;
        while (preNode.next != null) {
            ansArray[idx++] = preNode.next.val;
            preNode = preNode.next;
        }

        StringBuffer ans = new StringBuffer();
        ans.append(ansArray[1]);
        for (int i = 2; i <= n; i++) {
            ans.append(' ');
            ans.append(ansArray[i]);
        }
        System.out.println(ans);
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (Exception e) {
                return -1;
            }

            return (int) in.nval;
        }
    }

    static class Node {
        int val;
        Node next;

        public Node(int val) {
            this.val = val;
        }
    }

    static void remove(Node node) {
        node.next = node.next.next;
    }

}
